package com.fly.simple;

import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.apache.commons.lang3.StringUtils;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class MainRun
{
    public static void main(String[] args)
    {
        // docker-compose.yml -> environment -> USER
        String userEnv = System.getenv("USER");
        
        // java -jar xxx.jar --user=jackson
        String userArg = Stream.of(args).filter(arg -> arg.contains("--user")).map(arg -> StringUtils.substringAfter(arg, "=")).collect(Collectors.joining());
        
        // java -jar -Duser=jackson xxx.jar
        String userProp = System.getProperty("user", "");
        
        // 按优先级获取
        String userName = StringUtils.defaultIfBlank(userEnv, StringUtils.defaultIfBlank(userArg, userProp));
        
        log.info("userEnv: {}", userEnv);
        log.info("userArg: {}", userArg);
        log.info("userProp: {}", userProp);
        log.info("userName: {}", userName);
    }
}
